package com.he.hsdyc.common.log;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;


/**
 * 功能描述: 注解类的实现
 * @auther: tao
 * @date: 2019/6/28
 */

@Aspect
@Component
public class TaoLogAspect {

    private static final Logger LOG = LoggerFactory.getLogger(TaoLogAspect.class);

//    @Pointcut("execution(public * com.he.hsdyc.controller.AopController.index*(..))  ||  @annotation(com.he.hsdyc.common.log.annotation.TaoLogAnnotation)")
//    public void addAdvice(){}
//
//    @Before("addAdvice()")
//    public void before(JoinPoint joinPoint){
//        Object[] args = joinPoint.getArgs();
//        HttpServletRequest requests = (HttpServletRequest) args[0];
//        LOG.info("============打印日志开始============");
//        LOG.info("URL: " + requests.getRequestURL().toString());
//        LOG.info("============打印日志结束============");
//    }





    @Pointcut("execution(public * com.he.hsdyc.controller.AopController.index*(..))  ||  @annotation(com.he.hsdyc.common.log.annotation.TaoLogAnnotation)")
    private void cut() {}

    // 开始环绕   
    @Around("cut()")
    public void around (ProceedingJoinPoint joinPoint) throws Throwable {
        LOG.info("111111111111111111");
        try {
            joinPoint.proceed();
        }catch (Exception e) {
            e.printStackTrace();
        }
        LOG.info("444444444444444444");
    }

    @Before("cut()")
    public void before() {
        LOG.info("222222222222222222");
    }

    @After("cut()")
    public void after() {
        LOG.info("555555555555555555");
    }

}
